Skip to content

Method: lambda$interpolate$6(StringBuilder, Rational)

1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.media.impl.interpolator;
28:
29: import javax.annotation.Nonnull;
30: import java.text.DecimalFormat;
31: import java.util.Optional;
32: import it.tidalwave.image.metadata.EXIF;
33: import it.tidalwave.image.metadata.TIFF;
34: import it.tidalwave.image.metadata.XMP;
35:
36: /***********************************************************************************************************************
37: *
38: * @author Fabrizio Giudici
39: *
40: **********************************************************************************************************************/
41: public class ShootingDataInterpolator extends MetadataInterpolatorSupport
42: {
43: public ShootingDataInterpolator()
44: {
45: super("shootingData");
46: }
47:
48: @Override @Nonnull
49: public String interpolate (@Nonnull final String template, @Nonnull final Context context)
50: {
51: final var tiff = context.getMetadata().getDirectory(TIFF.class);
52: final var exif = context.getMetadata().getDirectory(EXIF.class);
53: final var xmp = context.getMetadata().getDirectory(XMP.class);
54: final var xmpProperties = xmp.getXmpProperties();
55: final var modelMap = context.getModelMap();
56: final var lensMap = context.getLensMap();
57:
58: final var builder = new StringBuilder();
59: final var cameraMake = tiff.getMake()
60: .or(exif::getMake)
61: .or(() -> Optional.ofNullable(xmpProperties.get("tiff:Make")))
62: .orElse("");
63: final var cameraModel = tiff.getModel()
64: .or(exif::getModel)
65: .or(() -> Optional.ofNullable(xmpProperties.get("tiff:Model")))
66: .orElse("");
67:
68: var camera = (cameraMake + ((!cameraModel.isBlank() && !cameraMake.isBlank()) ? " " : "") + cameraModel).trim();
69: camera = modelMap.getOrDefault(camera, camera);
70: builder.append(camera);
71: builder.append(" + ");
72:
73: final var lensMake = exif.getLensMake()
74: .or(() -> Optional.ofNullable(xmpProperties.get("exif:LensMake")))
75: .orElse("");
76: final var lensModel = exif.getLensModel()
77: .or(() -> Optional.ofNullable(xmpProperties.get("aux:Lens")))
78: .or(() -> Optional.ofNullable(xmpProperties.get("aux:LensID")))
79: .orElse("");
80:
81: var lens = (lensMake + ((!lensModel.isBlank() && !lensMake.isBlank()) ? " " : "") + lensModel).trim();
82: lens = lensMap.getOrDefault(lens, lens);
83:
84: builder.append(lens);
85: builder.append(" @ ");
86: exif.getFocalLength().ifPresent(fl -> builder.append(fl.intValue()).append(" mm, "));
87: // FIXME: eventually teleconverter
88: exif.getExposureTime().ifPresent(t -> builder.append(t).append(" sec @ ƒ/"));
89: exif.getFNumber().map(f -> new DecimalFormat("0.#").format(f.floatValue())).ifPresent(builder::append);
90:
91: exif.getExposureBiasValue().ifPresent(exposureBiasValue ->
92: {
93: if (exposureBiasValue.getNumerator() != 0)
94: {
95: builder.append(String.format(", %+.2f EV", exposureBiasValue.floatValue()));
96: }
97: });
98:
99: exif.getISOSpeedRatings().ifPresent(iso -> builder.append(", ISO ").append(iso.intValue()));
100:
101: return template.replace("$" + macro + "$", builder.toString());
102: }
103: }